Component({
  data: {
    selected: 0,
    list: [{
      pagePath: "/pages/home/home",
      text: "首页",
      icon: "🏠",
      selectedIcon: "🏠"
    }, {
      pagePath: "/pages/perfume/perfume",
      text: "香水推荐",
      icon: "🧴",
      selectedIcon: "🧴"
    }, {
      pagePath: "/pages/cocktail/cocktail",
      text: "制作特调",
      icon: "🍹",
      selectedIcon: "🍹"
    }, {
      pagePath: "/pages/profile/profile",
      text: "我的",
      icon: "👤",
      selectedIcon: "👤"
    }]
  },
  
  lifetimes: {
    attached() {
      // 获取当前页面路径
      const pages = getCurrentPages();
      const currentPage = pages[pages.length - 1];
      const route = currentPage.route;
      
      // 设置选中项
      this.data.list.forEach((item, index) => {
        if (item.pagePath.includes(route)) {
          this.setData({
            selected: index
          });
        }
      });
    },
  },
  
  methods: {
    switchTab(e) {
      const index = e.currentTarget.dataset.index;
      const item = this.data.list[index];
      
      // 更新选中状态
      this.setData({
        selected: index
      });
      
      // 跳转到对应页面
      wx.switchTab({
        url: item.pagePath
      });
    }
  }
}); 